import { createStore, applyMiddleware } from 'redux'
import reducer from './reducer'
import createSafaMiddleware from 'redux-saga'
import logger from 'redux-logger'
import { increase, decrease, asyncDecrease, autoIncrease, stopAutoIncrease } from './action/counter'
import { createChangeAction } from './action/student/searchCondition'
import { fetchStudents2 } from './action/student/searchResult'
import rootSaga from "./saga"

const sagaMid = createSafaMiddleware() // 创建一个saga的中间件
const store = applyMiddleware(sagaMid, logger)(createStore)(reducer)

// 启动saga任务
sagaMid.run(rootSaga)

// store.dispatch(asyncDecrease())
// store.dispatch(createChangeAction({ key: 'xxx' }))
// store.dispatch(fetchStudents2())

// canael
// store.dispatch(asyncDecrease())
// store.dispatch(asyncDecrease())
// store.dispatch(asyncDecrease())
// store.dispatch(asyncDecrease())
// fockTask只执行了一次

// store.dispatch(autoIncrease())
// store.dispatch(autoIncrease()) 
store.dispatch(autoIncrease())
setTimeout(() => {
    store.dispatch(stopAutoIncrease())
}, 5000)

export default store